package com.dididoctor.doctor.WYY.Medicaladvice;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dididoctor.doctor.Activity.GlobalParams;
import com.dididoctor.doctor.Activity.Order.DiagnosisDetails.DiagnosisDetailsActivity;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.LoaderImage;
import com.dididoctor.doctor.Utils.SharedPreferencesUtils;
import com.netease.nim.uikit.session.viewholder.MsgViewHolderBase;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;

/**
 * Created by zhoujianghua on 2015/8/4.
 */
public class MsgViewHolderMedicaladvice extends MsgViewHolderBase implements View.OnClickListener {

    private TextView tv_gusa_name,tv_gusa_age,tv_guess_medical_click;
    private LoaderImage loaderImage;
    private String disId;
    private String recId ;
    private String patientName ;
    private String age ;
    private String illName ;
    private String patientHeadPic;
    private String sex;
    @Override
    protected int getContentResId() {
        return R.layout.item_medical_advice;

    }

    @Override
    protected void inflateContentView() {
        loaderImage = new LoaderImage(GlobalParams.getContext());
        View ll_medical = view.findViewById(R.id.ll_medical);

        tv_gusa_name = (TextView) view.findViewById(R.id.tv_gusa_name);
        tv_gusa_age = (TextView) view.findViewById(R.id.tv_gusa_age);

        tv_guess_medical_click = (TextView) view.findViewById(R.id.tv_guess_medical_click);
        tv_guess_medical_click.setOnClickListener(this);

    }

    @Override
    protected void setLayoutParams(int width, int height, View... views) {
        View ll_medical = view.findViewById(R.id.ll_medical);
//        setLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,ll_medical);
        super.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, ll_medical);
    }

    @Override
    protected void bindContentView() {
        MedicaladviceAttachment attachment = (MedicaladviceAttachment) message.getAttachment();
        disId= attachment.getDisId();
        recId= attachment.getRecId();
        patientName= attachment.getPatientName();
        age = attachment.getAge();
        illName = attachment.getIllName();
        sex = attachment.getSex();
        patientHeadPic = attachment.getPatientHeadPic();
        tv_gusa_name.setText(attachment.getSuggestion());
        tv_gusa_age.setText(attachment.getSuggestionResult());

        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessdsiID", disId);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessRecId", recId);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuesspatientName", patientName);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "Guessage", age);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuessillName", illName);
        SharedPreferencesUtils.setParam(Token.getMcontext(), "GuesspatientHeadPic", patientHeadPic);

    }


    @Override
    protected boolean onItemLongClick() {

        return false;
    }


    private void layoutByDirection() {
        View ll_medical = findViewById(R.id.ll_medical);
        View tv_guess_medical_click = findViewById(R.id.tv_guess_medical_click);

        ViewGroup container = (ViewGroup) ll_medical.getParent();
        container.removeView(tv_guess_medical_click);
        if (isReceivedMessage()) {
            container.addView(tv_guess_medical_click, 1);
        } else {
            container.addView(tv_guess_medical_click, 0);
        }
        if (message.getStatus() == MsgStatusEnum.success) {
        } else {
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_guess_medical_click:
                if (message.getStatus() == MsgStatusEnum.success) {
                    Intent intent = new Intent(context, DiagnosisDetailsActivity.class);
                    intent.putExtra("recId",recId);
                    intent.putExtra("patientName",patientName);
                    intent.putExtra("age",age);
                    intent.putExtra("illName",illName);
                    intent.putExtra("patientHeadPic", patientHeadPic);
                    intent.putExtra("sex", sex);
                    context.startActivity(intent);
                }
                break;
        }

    }
}
